package com.mk.designMode.strategy.manager;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.nutz.ioc.Ioc;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.resource.Scans;

import com.mk.common.entity.annotation.BizType;
import com.mk.common.model.BizConditionDTO;
import com.mk.designMode.strategy.service.TreatCalcService;

/**
 * 资格待遇计算(业务逻辑层)
 * @author 上官雅晴
 * 不同业务的待遇计算规则不同，对应的有不同的接口实现
 */
@IocBean
public class TreatCalcManager {
	@Inject
	Ioc ioc;
	
	/**
	 * 初始化
	 */
	private static Map<String,Class<?>> classMap = new HashMap<>();
	static {
		List<Class<?>> clazzList =  Scans.me().scanPackage("com.mk.designMode.strategy.service.impl");
		int numOfChildCalss = clazzList.size();
		for(int i=0; i<numOfChildCalss; i++) {
			Class<?> clazz = clazzList.get(i);
			BizType bizAnnotation = clazz.getAnnotation(BizType.class);
			if(bizAnnotation==null)
				continue;
			String bizNo = bizAnnotation.value(); //注解值
			if(bizNo==null || "".equals(bizNo))
				continue;
			//存储
			classMap.put(bizNo, clazz);
		}
	}
	
	
	/**
	 * 计算
	 * @param bizCdn
	 */
	public void calcTreat(BizConditionDTO bizCdn) {
		String bizNo = bizCdn.getBizNo(); 
		if(bizNo==null || "".equals(bizNo))
			throw new RuntimeException("业务编号不能为空！");
		if(!classMap.containsKey(bizNo)) 
			throw new RuntimeException("没有对应计算方法！");
		
		//获取对应实例，并 做计算
		Class<?> class_ = classMap.get(bizNo);
		TreatCalcService treatCalcService = (TreatCalcService) ioc.get(class_);
		treatCalcService.calcFund();
	}
}
